package com.foreveross.vo;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

import com.foreveross.util.NotSerialize;
import com.foreveross.vo.common.AffiliatedBaseVo;

/**
 * SysMenu entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "sys_menu", catalog = "hrtenement")
public class SysMenu extends AffiliatedBaseVo implements java.io.Serializable {

	// Fields

	private String id;
	private String name;
	private String url;
	private SysMenu parent;
	private String parentName;
	private Integer menuNo;
	private String description;
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date creationTime;
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date updateTime;
	private String parentid;

	// Constructors

	/** default constructor */
	public SysMenu() {
	}

	/** minimal constructor */
	public SysMenu(String id) {
		this.id = id;
	}

	/** full constructor */
	public SysMenu(String id, String name, String url, SysMenu parent) {
		this.id = id;
		this.name = name;
		this.url = url;
		this.parent = parent;
	}

	// Property accessors
	@Id
	@GenericGenerator(name = "idGenerator", strategy = "uuid")
	@GeneratedValue(generator = "idGenerator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "name")
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "url")
	public String getUrl() {
		return this.url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parentId", nullable = true)
	@NotFound(action = NotFoundAction.IGNORE)
	public SysMenu getParent() {
		return this.parent;
	}

	public void setParent(SysMenu parent) {
		this.parent = parent;
	}

	@Transient
	public String getParentName() {
		if (parent != null)
			return parent.getName();
		else
			return this.parentName;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}

	@Column(name = "menu_no")
	public Integer getMenuNo() {
		return menuNo;
	}

	public void setMenuNo(Integer menuNo) {
		this.menuNo = menuNo;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "creation_time")
	public Date getCreationTime() {
		return creationTime;
	}

	public void setCreationTime(Date creationTime) {
		this.creationTime = creationTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Transient
	public String getParentid() {
		if (parent != null)
			return parent.getId();
		else
			return parentid;
	}

	public void setParent_id(String parentid) {
		this.parentid = parentid;
	}

}